package com.shop2cn.app.liveseller.testcase;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;



import com.shop2cn.app.liveseller.parameter.*;
import com.shop2cn.app.liveseller.service.*;
import com.shop2cn.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.shop2cn.iapi.couponmanage.service.SellerCreateBatchCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.*;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
import com.ymttest.utils.TestDataManager;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*发放优惠券批次
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SendCoupon{
	private static SendCouponBean sendcouponBean;
	private static SendCouponCall sendcouponCall;
	private static int sellerId;
	private static String token;
	private static int csId;
	private static String cstoken;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发放优惠券批次");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
			csId = GodmchManageCallService.bindClientService(
					sellerId, 1);
			cstoken = AuthCallServiceV2.createToken(csId, "app");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		sendcouponBean=new SendCouponBean();
		sendcouponCall=new SendCouponCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(sendcouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendCoupon_001() {
		Logger.start(true,"发放优惠券批次");
		try {
			SellerCreateBatchBean sellercreatebatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			sellercreatebatchBean.setSellerId(sellerId);
			SellerCreateBatchCall sellerCreateBatchCall = CouponShop2cnMCallService.SellerCreateBatch(sellercreatebatchBean);
			
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			
			//sellerCreateBatchCall.getBatchCode();
			sendcouponBean.setLiveId(createlive.getId());
			sendcouponBean.setBatchCode(sellerCreateBatchCall.getBatchCode());
			sendcouponCall.setData(sendcouponBean);
			String head="accesstoken="+token;
			Logger.debug("ymt-pars:"+ head);
			sendcouponCall.addHeader("ymt-pars", head);
			sendcouponCall.callService();			
			Logger.verifyEquals("true", sendcouponCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendCoupon_002() {
		Logger.start(true,"客服发放优惠券批次");
		try {
			SellerCreateBatchBean sellercreatebatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			sellercreatebatchBean.setSellerId(sellerId);
			SellerCreateBatchCall sellerCreateBatchCall = CouponShop2cnMCallService.SellerCreateBatch(sellercreatebatchBean);
			
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			
			//sellerCreateBatchCall.getBatchCode();
			sendcouponBean.setLiveId(createlive.getId());
			sendcouponBean.setBatchCode(sellerCreateBatchCall.getBatchCode());
			sendcouponCall.setData(sendcouponBean);
			String head="accesstoken="+cstoken;
			Logger.debug("ymt-pars:"+ head);
			sendcouponCall.addHeader("ymt-pars", head);
			sendcouponCall.callService();			
			Logger.verifyEquals("true", sendcouponCall.getString("success"), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}